package utils;

import mappings.AppliancesComposition;
import mappings.ProducentComposition;
import mappings.TypesComposition;

import java.util.List;
import java.util.Set;

public class MergeUtil
{
    /*
     *  Laczy wszystkich producentow w 1 string (do reprezentacji xml)
     */
    public static String mergeProducentsIntoOneString(Set<ProducentComposition> producentCompositions)
    {
        StringBuilder stringBuilder = new StringBuilder();
        boolean foundAnyProducent = false;

        for(ProducentComposition producentComposition : producentCompositions)
        {
            foundAnyProducent = true;

            stringBuilder.append(producentComposition.getProducent().getName());
            stringBuilder.append(",");
        }

        // usuwanie przecinka z konca :P
        if(foundAnyProducent)
        {
            stringBuilder.deleteCharAt(stringBuilder.length()-1);
        }

        return stringBuilder.toString();
    }

    /*
     *  Laczy wszystkie types w 1 string (do reprezentacji xml)
     */
    public static String mergeTypesIntoOneString(Set<TypesComposition> typesCompositionSet)
    {
        StringBuilder stringBuilder = new StringBuilder();
        boolean foundAnyType = false;

        for (TypesComposition typesComposition : typesCompositionSet)
        {
            foundAnyType = true;

            stringBuilder.append(typesComposition.getTypes().getName());
            stringBuilder.append(",");
        }

        // usuwanie przecinka z konca :P
        if (foundAnyType)
        {
            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
        }

        return stringBuilder.toString();
    }

    /*
     *  Laczy wszystkie appliances w 1 string (do reprezentacji xml)
     */
    public static String mergeAppliancesIntoOneString(List<AppliancesComposition> appliancesCompositions)
    {
        StringBuilder stringBuilder = new StringBuilder();
        boolean foundAnyAppliance = false;

        for (AppliancesComposition appliancesComposition : appliancesCompositions)
        {
            foundAnyAppliance = true;

            stringBuilder.append(appliancesComposition.getAppliances().getName());
            stringBuilder.append(",");
        }

        // usuwanie przecinka z konca :P
        if (foundAnyAppliance)
        {
            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
        }

        return stringBuilder.toString();
    }
}
